package com.lingang.framework.web.enums;

import lombok.Getter;

/**
 * 请求状态
 *
 * @author zhangkaicheng
 */
@Getter
public enum ApiRequestStatusEnum {
    /**
     * 请求状态
     */
    ERROR(0, "操作失败"),
    SUCCESS(200, "操作成功"),
    BAD_REQUEST(400, "数据格式有误"),
    PERMISSION_REQUIRE(401, "用户未登录"),
    ACCESS_DENIED(403, "用户权限不足"),
    NOTFOUND(404, "接口不存在"),
    METHOD_NOT_ALLOWED(405, "请求方法错误"),
    GONE(410, "资源已过期"),
    SERVER_INTERNAL_ERROR(500, "服务器内部错误"),
    START_DATE_NOT_NULL(601, "开始日期不能为空"),
    END_DATE_NOT_NULL(602, "结束日期不能为空"),
    UNIT_NOT_NULL(603, "单位不能为空"),
    /**
     * 用于接口熔断返回
     */
    BUSY_ERROR(999, "系统繁忙，请稍后再试！");

    private final Integer code;

    private final String message;

    ApiRequestStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static ApiRequestStatusEnum getStatusByCode(Integer code) {
        for (int i = 0; i < values().length; i++) {
            if (values()[i].code.equals(code)) {
                return values()[i];
            }
        }
        return null;
    }
}
